using Services;

public class ShopUI_Manager : MyCanvasGrounp
{
    public CommodityContainer Container { get; private set; }
    public Player Player { get; private set; }
    public TraderData Data { get; private set; }
    public ShopUI_DialogBox Box { get; private set; }
    public ShopUI_TachiE TachiE { get; private set; }

    private void Start()
    {
        ServiceLocator.Get<EventSystem>().AddListener<EGameState, EGameState>(EEvent.GameStateChange, OnGameStateChange);
        Box = GetComponentInChildren<ShopUI_DialogBox>();
        TachiE = GetComponentInChildren<ShopUI_TachiE>();
        Player = ServiceLocator.Get<ActionController>().player;
    }

    private void OnGameStateChange(EGameState from, EGameState to)
    {
        switch (to)
        {
            case EGameState.Purchase:
                Visible = true;
                Container = Player.LeftContainer as CommodityContainer;
                Data = Container.GetComponent<TraderData>();
                TachiE.Show(Data.traderTachiE);
                Box.Initialize(Data.dialogs);
                break;
            default:
                Visible = false;
                Box.Hide();
                break;
        }
    }
}
